local humei = fk.CreateSkill {

  name = "joy_humei",

  tags = {  },

}



humei:addEffect("active", {
  name = "joy_humei",
  anim_type = "control",
  card_num = 0,
  target_num = 1,
  prompt = function(self)
    return "狐魅：令一名角色执行一项"
  end,
  interaction = function(self,player)
    local choices = {}
    for i = 1, 3, 1 do
      if player:getMark("joy_humei"..i.."-turn") == 0 then
        table.insert(choices, "joy_humei"..i.."-turn")
      end
    end
    return UI.ComboBox { choices = choices }
  end,
  can_use = function(self, player)
    for i = 1, 3, 1 do
      if player:getMark("joy_humei"..i.."-turn") == 0 then
        return player:usedSkillTimes("joy_humei", Player.HistoryPhase) < player:getMark("@joy_humei-phase")
      end
    end
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected)
    local target = Fk:currentRoom():getPlayerById(to_select)
    if #selected == 0  then
      if self.interaction.data == "joy_humei1-turn" then
        return true
      elseif self.interaction.data == "joy_humei2-turn" then
        return not target:isNude()
      elseif self.interaction.data == "joy_humei3-turn" then
        return target:isWounded()
      end
    end
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    room:setPlayerMark(player, self.interaction.data, 1)
    if self.interaction.data == "joy_humei1-turn" then
      target:drawCards(1, humei.name)
    elseif self.interaction.data == "joy_humei2-turn" then
      local card = room:askForCard(target, 1, 1, true, humei.name, false, ".", "#joy_humei-give:"..player.id)
      room:obtainCard(player, card[1], false, fk.ReasonGive, target.id)
    elseif self.interaction.data == "joy_humei3-turn" then
      room:recover{
        who = target,
        num = 1,
        recoverBy = player,
        skillName = humei.name
      }
    end
  end,
})

humei:addEffect(fk.Damage, {
  name = "#joy_humei_trigger",
  events = {fk.Damage},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(humei.name) and player.phase == Player.Play and player:getMark("@joy_humei-phase") < 3
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room  = player.room
    room:notifySkillInvoked(player, humei.name, "special")
    player:broadcastSkillInvoke(humei.name)
    player.room:setPlayerMark(player, "@joy_humei-phase",math.min(player:getMark("@joy_humei-phase") + data.damage,3))
  end,
})
humei:addEffect(fk.EventAcquireSkill, {
  refresh_events = {fk.EventAcquireSkill},
  can_refresh = function (self, event, target, player, data)
    return target == player and data == self and player.phase == Player.Play
  end,
  on_refresh = function (self, event, target, player, data)
    local n = 0
    player.room.logic:getActualDamageEvents(1, function(e)
      if e.data[1].from == player then
        n = n + e.data[1].damage
      end
    end,Player.HistoryPhase)
    player.room:setPlayerMark(player, "@joy_humei-phase",math.min(3,n))
  end,
})

return humei